feat: add MicProlongedUsage detection event#3681
Merged
Conversation
Per-app timer that fires after 3 minutes of mic usage when Hyprnote is not actively listening. Timers are cancelled when the app stops using the mic. Co-Authored-By: yujonglee <yujonglee.dev@gmail.com>
✅ Deploy Preview for hyprnote-storybook canceled.
|
✅ Deploy Preview for hyprnote canceled.
|
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: yujonglee <yujonglee.dev@gmail.com>
Co-Authored-By: yujonglee <yujonglee.dev@gmail.com>
Co-Authored-By: yujonglee <yujonglee.dev@gmail.com>
…rt race Co-Authored-By: yujonglee <yujonglee.dev@gmail.com>
…state Co-Authored-By: yujonglee <yujonglee.dev@gmail.com>
Co-Authored-By: yujonglee <yujonglee.dev@gmail.com>
Co-Authored-By: yujonglee <yujonglee.dev@gmail.com>
Co-Authored-By: yujonglee <yujonglee.dev@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: add MicProlongedUsage detection event
Summary
Adds a new
DetectEvent::MicProlongedUsagevariant that fires when an app has been using the mic for 3 minutes continuously. The frontend then decides whether to show a notification based on the current listener state and user settings. This enables prompting users to start recording when they appear to be in a meeting.How it works:
Rust (detect plugin):
MicStartedis received for an app (that passes policy + cooldown filtering), a per-app timer is spawned with a 3-minute threshold usingCancellationTokenstd::sync::Mutexstate lock, callsclaim()with the generation number to atomically verify and remove the entry, then emitsMicProlongedUsageMicStoppedis received, the timer'sCancellationTokenis cancelled and the entry removedis_in_cooldown()to prevent unbounded map growth.tauri-plugin-listenerdependency is removed from the detect plugin — the "is listening" check is intentionally moved to the consumer side (frontend)Frontend:
listener.tsxhandles the newmicProlongedUsageevent, checking both thenotification_in_meeting_remindersetting andstore.getState().live.status === "active"before showing a notificationMeetingReminderTogglein Settings > Lab lets users enable/disable the feature (default: enabled)Race condition mitigations:
claim()only succeeds if the generation matches, preventing stale timers from emitting after a stop+restart cycle.tokio::select!between sleep and cancellation ensures prompt abort onMicStopped.claim(), the app enters a 1-hour cooldown, suppressing duplicate notifications.Key files changed:
plugins/detect/src/mic_usage_tracker.rs— new module:MicUsageTrackerwith generation-based timers, cooldowns (with lazy expiry cleanup), and comprehensive unit testsplugins/detect/src/env.rs— new module:Envtrait abstracting event emission + DnD checks for testabilityplugins/detect/src/handler.rs— refactored to useEnvtrait; added integration-style testsplugins/detect/src/events.rs— newMicProlongedUsagevariant (replaces oldFromimpl)plugins/detect/src/policy.rs— removedis_listening/skip_when_listening; addedshould_track_app();user_ignored_bundle_idschanged toHashSetplugins/detect/src/lib.rs— split intoDetectorState+ProcessorState;std::sync::Mutexinstead oftokio::sync::Mutexapps/desktop/src/contexts/listener.tsx— handlesmicProlongedUsagewith listener state + setting checksapps/desktop/src/components/settings/lab/index.tsx— newMeetingReminderTogglecomponentReview & Testing Checklist for Human
bindings.gen.tswas hand-edited. Regenerate viacargo test -p tauri-plugin-detectto verify it matches.store.getState().live.status === "active"at notification time. If user starts listening between timer fire and notification display, the notification is correctly suppressed. Verify this works as expected.MicStarted/MicStoppednotifications respect DnD). Confirm this is intentional behavior.Notes
MIC_ACTIVE_THRESHOLD). Cooldown is 1 hour (COOLDOWN_DURATION). Could be made configurable later.MicUsageTrackerand integration-style tests inhandler.rs.is_in_cooldown()is called (not via periodic task), which is sufficient since the map is bounded by the number of distinct apps that have triggered timers.Link to Devin run: https://app.devin.ai/sessions/0abeb320269b434cade8e4591a698c6e
Requested by: @yujonglee